package com.zqp.security.core.validator.code;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 
* @author zqp
* @version2017年12月21日 
* @description
 */
@RestController
public class ValidateCodeController {

	@Autowired
	private ValidateCodeProcessorHolder validateCodeProcessorHolder;
	/**
	 * 创建验证码 根据验证码的类型的不同 ,调用不同的 ${@link ValidateCodeProcessor}} 接口的实现
	 * @param request
	 * @param type
	 * @throws Exception
	 * @see
	 */
	@GetMapping("/code/{type}")
	public void createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable String type) throws Exception {
//		ImageCode  imageCode = (ImageCode) iamgeCodeGenerator.createCode((new ServletWebRequest(request)));
//		//放入session 中
//		ImageIO.write(imageCode.getImage(), "JPEG", response.getOutputStream());
//		validateCodeProcessors.get(type+"CodeProcessor").createCode((new ServletWebRequest(request,response)));
		validateCodeProcessorHolder.findValidateCodeProcessor(type).createCode(new ServletWebRequest(request, response));
		
	}
	

}
